package com.mdc.mansion.web.modules.basedata.web;

import com.mdc.mansion.core.modules.restaurant.RestaurantService;
import com.mdc.mansion.dataaccess.modules.restaurant.entity.Restaurant;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.mdc.mansion.web.modules.system.utils.UserUtils;
import com.mdc.mansion.dataaccess.modules.system.entity.User;

import com.mdc.mansion.dataaccess.common.persistence.Page;
import com.mdc.mansion.dataaccess.modules.basedata.entity.QrcodeUseLog;
import com.mdc.mansion.core.modules.basedata.QrcodeUseLogService;
import com.mdc.mansion.web.common.web.BaseController;
/**
 * 二维码批量生成报表Controller
 * @author xizf
 * @version 2018-04-09
 */
@Controller
@RequestMapping(value = "${adminPath}/basedata/qrcodeUseLog")
public class QrcodeUseLogController extends BaseController {

	@Autowired
	private QrcodeUseLogService qrcodeUseLogService;

	@Autowired
	private RestaurantService restaurantService;
	
	@ModelAttribute
	public QrcodeUseLog get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return qrcodeUseLogService.get(id);
		}else{
			return new QrcodeUseLog();
		}
	}
	
	@RequiresPermissions("basedata:qrcodeUseLog:view")
	@RequestMapping(value = {"list", ""})
	public ModelAndView list(QrcodeUseLog qrcodeUseLog) {
		Map<String, Object> model=new HashMap<String, Object>();
		Page<QrcodeUseLog> page = qrcodeUseLogService.findPage(qrcodeUseLog);
		List<Restaurant> list = restaurantService.findList(new Restaurant());
		model.put("restaurants",list);
        model.put("page", page);
		ModelAndView modelAndView=new ModelAndView("modules/basedata/qrcodeUseLogList", model);
		return modelAndView;
	}
	
	@RequiresPermissions("basedata:qrcodeUseLog:view")
	@RequestMapping(value = "findQrCodeSummry")
	public ModelAndView findQrCodeSummry(QrcodeUseLog qrcodeUseLog) {
		Map<String, Object> model=new HashMap<String, Object>();
		List<QrcodeUseLog> qrcodeList = qrcodeUseLogService.findQrCodeSummry(qrcodeUseLog);
		List<Restaurant> list = restaurantService.findList(new Restaurant());
		model.put("restaurants",list);
        model.put("sumaryList", qrcodeList);
        model.put("pageNo", 0);
        model.put("pageSize", 0);
		ModelAndView modelAndView=new ModelAndView("modules/basedata/qrcodeUseLogList", model);
		return modelAndView;
	}
	
	
	@RequiresPermissions("basedata:qrcodeUseLog:view")
	@RequestMapping(value = "form")
	public ModelAndView form(QrcodeUseLog qrcodeUseLog) {
		Map<String, Object> model=new HashMap<String, Object>();
		model.put("qrcodeUseLog", qrcodeUseLog);
		return new ModelAndView("modules/basedata/qrcodeUseLogForm",model);
	}
	

	@RequiresPermissions("basedata:qrcodeUseLog:edit")
	@RequestMapping(value = "save")
	public ModelAndView save(QrcodeUseLog qrcodeUseLog,RedirectAttributes redirectAttributes) {
		User u=UserUtils.getUser();
		qrcodeUseLog.setUpdateBy(u);
		if (StringUtils.isNotBlank(qrcodeUseLog.getId())){
			qrcodeUseLogService.updateSelective(qrcodeUseLog);
		}else{
			qrcodeUseLog.setCreateBy(u);
			qrcodeUseLogService.save(qrcodeUseLog);
		}
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
	@RequiresPermissions("basedata:qrcodeUseLog:edit")
	@RequestMapping(value = "delete")
	public ModelAndView delete(QrcodeUseLog qrcodeUseLog,RedirectAttributes redirectAttributes) {
		qrcodeUseLogService.delete(qrcodeUseLog);
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
}
